#include "stdafx.h"
#include "HeaderControlExample.h"

#include "hwinapplication.h"
#include "hwinform.h"
#include "hwinmenu.h"
#include "hwinstdctrls.h"
#include <iostream>

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

using namespace harlinn::windows;

class HeaderControlForm : public Form
{
    std::shared_ptr<HeaderControl> headerControl;
public:
    typedef Form Base;
    HeaderControlForm();
protected:
    virtual void DoOnInitialize();
    virtual void DoOnSize(Message& message);
    virtual void DoOnPaint(Message& message);
};


HeaderControlForm::HeaderControlForm()
    : Base()
{
    SetText(L"HeaderControl example");
    SetSize(300,70);
}

void HeaderControlForm::DoOnInitialize()
{
    Base::DoOnInitialize(); 
    auto self = As<HeaderControlForm>();
    headerControl = make_control<HeaderControl>(self);
    headerControl->Items()->Add(String(L"First"));
    headerControl->Items()->Add(String(L"Second"));
}


void HeaderControlForm::DoOnSize(Message& message)
{
    harlinn::windows::Rectangle clientRect = GetClientRect();
    headerControl->MoveWindow(0,0,clientRect.Width(),21);
}

void HeaderControlForm::DoOnPaint(Message& message)
{
    Base::DoOnPaint(message);
    auto dc = std::make_shared<PaintDeviceContextHandle>(As<Control>());
    dc->DrawDesktopWallPaper();
}

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
    try
    {
        auto application = make_component<Application>();
        auto form = make_control<HeaderControlForm>();
        
        auto result = application->Run(form);

        return result;
    }
    catch(std::exception& exc)
    {
        std::cout << exc.what() << std::endl;
    }
    catch(...)
    {
        std::cout << "Unknown exception" << std::endl;    
    }
    return 0;
}